import { MedicalModel } from '../models/medical.js';

export const MedicalController = {
  async getAllRecords(req, res) {
    try {
      const records = await MedicalModel.getAllRecords();
      res.json(records);
    } catch (error) {
      res.status(500).json({ error: 'Failed to fetch medical records' });
    }
  },

  async createRecord(req, res) {
    try {
      const id = await MedicalModel.createRecord(req.body);
      res.status(201).json({ id, ...req.body });
    } catch (error) {
      res.status(500).json({ error: 'Failed to create medical record' });
    }
  },

  async updateRecord(req, res) {
    try {
      const success = await MedicalModel.updateRecord(req.params.id, req.body);
      if (success) {
        res.json({ id: req.params.id, ...req.body });
      } else {
        res.status(404).json({ error: 'Medical record not found' });
      }
    } catch (error) {
      res.status(500).json({ error: 'Failed to update medical record' });
    }
  }
};